var gulp = require('gulp'),
    jshint = require('gulp-jshint'),//jshint仅仅是javascript的语法检查工具，检测不出来我们的逻辑问题；也不能用于代码的压缩与合并，其他的功能则需要其相应的模块进行处理
    webpack = require('gulp-webpack'),//
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    webpackConfig = require('./webpack.config.js'),
    clean = require('gulp-clean');
    //process = require('child_process');

/*gulp.task('lint', function  () {
  gulp.src('./js/!*.js') /// 检查文件：js目录下所有的js文件
    .pipe(jshint())  // 进行检查
    .pipe(jshint.reporter('default')); //// 对代码进行报错提示
});*/

/*for build */
gulp.task('webpack', function() {
  gulp.src('src/main.js')
    .pipe(webpack(webpackConfig))
    .pipe(gulp.dest('./dist'));
  gulp.src('build/jquery/dist/jquery.js')
    .pipe(gulp.dest('./dist'));
  gulp.src('build/layer/src/**/**/*')
    .pipe(gulp.dest('./dist'));
  gulp.src('build/laypage/src/**/*')
    .pipe(gulp.dest('./dist'));
  gulp.src('src/js/*.js')
    .pipe(gulp.dest('./dist'));
  gulp.src('src/js/**/*.js')
    .pipe(gulp.dest('./dist'));
  gulp.src('src/js/jqueryUi/**/*')
    .pipe(gulp.dest('./dist/jqueryUi'));
});
gulp.task('watch', function () {
    gulp.watch('src/components/**/*.js', ['webpack']);
    gulp.watch('src/components/**/*.less', ['webpack']);
    gulp.watch('src/components/**/*.html', ['webpack']);
    gulp.watch('src/**/*.js', ['webpack']);
    gulp.watch('src/**/*.less', ['webpack']);
    gulp.watch('build/**/*.js', ['webpack']);
    gulp.watch('build/**/*.css', ['webpack']);
    gulp.watch('build/**/*.html', ['webpack']);
});
gulp.task('webserver', function() {
  process.exec('node ./bin/startup.js');
});


gulp.task('clean', function() {
    gulp.src('./dist/', {
        read: false
    })
    .pipe(clean());
});

gulp.task('default',[ 'webpack'], function(){
    gulp.start(['watch']);
});
